//
//  XDLoadingView.m
//  xindailianmeng
//
//  Created by 张东 on 2017/2/21.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.
//

#import "XDLoadingView.h"

@implementation XDLoadingView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
   
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 30)];
    [self addSubview:view];
        //    创建CAReplicatorLayer
        CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
        
        //    添加到self.view.layer上
    [view.layer addSublayer:replicatorLayer];
        
        
        //    添加一个震动层
        CALayer *vibrateLayer = [CALayer layer];
        
        vibrateLayer.anchorPoint = CGPointMake(0.5, 1);
        
        
        
        vibrateLayer.cornerRadius = 20/2;
        vibrateLayer.masksToBounds = YES;
        
        //        vibrateLayer.bounds = CGRectMake(0, 0, 20, 20);
        //        vibrateLayer.position = CGPointMake(10, replicatorLayer.frame.size.height/2 + 10);
        ////        187,147,115
        vibrateLayer.backgroundColor = [UIColor colorWithRed:187/255.0 green:147/255.0 blue:115/255.0 alpha:1].CGColor;
        [replicatorLayer addSublayer:vibrateLayer];
        
        replicatorLayer.instanceCount = 3;
        CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
        
        keyframeAnimation.duration = 1;
        keyframeAnimation.values = @[@(0.1),@(1),@(0.1)];
        
        keyframeAnimation.repeatCount = MAXFLOAT;
        
        [vibrateLayer addAnimation:keyframeAnimation forKey:@"SVRefreshView"];
        
        replicatorLayer.instanceTransform = CATransform3DMakeTranslation(20, 0, 0);
        replicatorLayer.instanceDelay = 0.1;
        
            
          replicatorLayer.position = CGPointMake([UIScreen mainScreen].bounds.size.width * 0.5, 60 * 0.5);
           replicatorLayer.bounds = CGRectMake(0, 0, 60, 60);
            
         vibrateLayer.bounds = CGRectMake(0, 0, 20, 20);
         vibrateLayer.position = CGPointMake(10, replicatorLayer.frame.size.height/2 + 10);

        
    }
    return  self;
}
@end
